﻿using Modules.BankSpecialAccount;
using Modules.Common;
using Modules.Payroll;
using Modules.Project;
using PmSoft;

namespace ManagementApi.Services
{
    /// <summary>
    /// 流水号相关service
    /// </summary>
    [UseDI(ServiceLifetime.Scoped)]
    public class SerialNumberService
    {
        private readonly ProjectService projectService;
        private readonly BankSpecialAccountService projectSpecialAccountService;
        private readonly ProjectSecurityDepositService projectSecurityDepositService;
        private readonly WagePayrollService payrollService;

        public SerialNumberService(ProjectService projectService, BankSpecialAccountService projectSpecialAccountService, ProjectSecurityDepositService projectSecurityDepositService, WagePayrollService payrollService)
        {
            this.projectService = projectService;
            this.projectSpecialAccountService = projectSpecialAccountService;
            this.projectSecurityDepositService = projectSecurityDepositService;
            this.payrollService = payrollService;
        }

        /// <summary>
        /// 生成流水号和单据号
        /// </summary>
        /// <param name="type"></param>
        /// <param name="projectNum"></param>
        /// <param name="projectId"></param>
        /// <returns></returns>
        public (string Code, int SerialNumber) GetNumAndSerialNumber(SerialNumberType type, string projectNum = "", int projectId = 0)
        {
            switch (type)
            {
                case SerialNumberType.专户:
                    return ("ZH" + DateTime.Now.GetTimeStamp().ToString(), 0);
                // return projectSpecialAccountService.GetNumAndSerialNumber(projectNum, projectId);
                case SerialNumberType.保证金:
                    return ("BZJ" + DateTime.Now.GetTimeStamp().ToString(), 0);
                //return projectSecurityDepositService.GetNumAndSerialNumber(projectNum, projectId);
                case SerialNumberType.工资单:
                    return ("GZD" + DateTime.Now.GetTimeStamp().ToString(), 0);
                //return payrollService.GetNumAndSerialNumber(projectNum, projectId);
                default:
                    return ("", 0);
            }
        }

        /// <summary>
        /// 生成编号
        /// </summary>
        /// <param name="type">类型</param>
        /// <param name="projectNum">项目编号</param>
        /// <param name="projectId">项目id</param>
        /// <returns></returns>
        public string GetSerialNumber(SerialNumberType type, string projectNum, int projectId)
        {
            string serialNumber = "";
            switch (type)
            {
                case SerialNumberType.专户:
                    serialNumber = DateTime.Now.GetTimeStamp().ToString();
                    break;

                case SerialNumberType.保证金:
                    serialNumber = projectSecurityDepositService.GetCode(projectNum, projectId);
                    break;

                case SerialNumberType.工资单:
                    serialNumber = payrollService.GetCode(projectNum, projectId);
                    break;
                default:
                    break;
            }
            return serialNumber;
        }
    }
}